﻿using FilterWebApp.Models;
using FilterWebApp.Utils.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace FilterWebApp.Controllers
{
    [CustomControllerActionFilter]
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
            Console.WriteLine("正在执行HomeController构造函数。。。");
            //_logger.LogInformation("Log：正在执行HomeController构造函数。。。");
        }

        [CustomActionFilter] //是一个特性，故可以去掉后面的Attribute，无参
        //[TypeFilter(typeof(CustomActionFilterAttribute))]//此时不是特性，故需要完整类名
        //[ServiceFilter(typeof(CustomActionFilterAttribute))]
        public IActionResult Index()
        {
            Console.WriteLine("正在执行HomeController的Index函数。。。");
           // _logger.LogInformation("Log：正在执行HomeController的Index函数。。。");
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
